<?php

/**

 * Created by PhpStorm.

 * User: zhoujun

 * Date: 2018/9/1

 * Time: 11:58

 */



namespace addons\faqueue\library\jobs;



use addons\faqueue\model\FaqueueLog;
use app\admin\model\gongcheng\xiangmu\Chengben;
use think\Log;

use think\queue\job;
use CURLFile;
use think\Db;
use think\Exception;
use fast\Yongyou;
use fast\DeliveryNoteGenerator;
use fast\CloudPrinter;

class OrderDaying

{

    public function fire(Job $job, $data){





        $ret = false;

        

        try {
            $generator = new DeliveryNoteGenerator();
            $file = $generator->addOrder($data);
            $cloud_printer = new CloudPrinter();
            $device_port = "1";
            $printer_model = "24针针打通用驱动 80列" ;

            if (!empty($file)) {
                $realPath = realpath($file);
                if ($realPath && file_exists($realPath)) {
                    $curlFile = new CURLFile($realPath);
                    $task = $cloud_printer->addJob($device_port, $printer_model, 602, $curlFile);

                    
                } else {
                    logs('order_daying','订单ID----'.$data.'-----生成的订单文件不存在');    
                }
            }


        } catch (Exception $e) {
             logs('order_daying','订单ID----'.$data.'-----队列报错'.$e->getError());    
        }


        $job->delete();
        (new FaqueueLog())->log($job->getQueue(),$job->getName(),$data);


    }



     public function failed($data){

        Log::write("链账户上链失败".print_r(['data' => $data,],true),'error');

    }

}